

using System;
using System.Collections.Generic;
using System.Text;

using log4net;
using log4net.Config;
using log4net.Repository.Hierarchy;
using log4net.Appender;
using System.Web.Configuration;

namespace JTC.MiniCommerce.Core {
  public class Logger {
  
    #region Constants
    // TODO: change this value
    private const string LOGGER_NAME = "MiniCommerce";
    private const string APPENDER_NAME = "AdoNetAppender";
    
    #endregion
    
    #region Member Variables 

    private static readonly ILog _log = LogManager.GetLogger(LOGGER_NAME);
    
    #endregion
    
    #region Constructors

    /// <summary>
    /// Initializes a new instance of the <see cref="T:Logger"/> class.
    /// </summary>
    private Logger() {
    }

    /// <summary>
    /// Initializes the <see cref="T:Logger"/> class.
    /// </summary>
    static Logger() {
      XmlConfigurator.Configure();
      Hierarchy hierarchy = LogManager.GetRepository() as Hierarchy;
      if(hierarchy != null) {
        AdoNetAppender adoNetAppender = (AdoNetAppender)hierarchy.GetLogger(LOGGER_NAME, hierarchy.LoggerFactory).GetAppender(APPENDER_NAME);
        if(adoNetAppender != null) {
          adoNetAppender.ConnectionString = WebConfigurationManager.ConnectionStrings[LOGGER_NAME].ConnectionString;
          adoNetAppender.ActivateOptions();
        }
      }
    }

    #endregion
    
    #region Methods
    
    #region Public

    public static void Error(object message, Exception ex) {
      _log.Error(message, ex);
    }
    
    public static void Error(string message) {
      _log.Error(message);
    }
    
    #endregion
    
    #endregion

  }
}
